package com.xnyzc.lhy.finance.service.impl.wallet;

import com.xnyzc.lhy.common.util.IDUtil;
import com.xnyzc.lhy.finance.entity.wallet.OaDWalletRecord;
import com.xnyzc.lhy.finance.mapper.wallet.OaDWalletRecordMapper;
import com.xnyzc.lhy.finance.service.wallet.IOaDWalletRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>
 * 用户钱包记录表 服务实现类
 * </p>
 *
 * @author cuixiaojian
 * @since 2019-10-16
 */
@Service
public class OaDWalletRecordServiceImpl extends ServiceImpl<OaDWalletRecordMapper, OaDWalletRecord> implements IOaDWalletRecordService {

    @Autowired
    private OaDWalletRecordMapper oaDWalletRecordMapper;

    /**
     * 保存钱包变动记录
     * @param driverId 司机ID
     * @param amount 钱
     * @param date 当期时间
     * @param recordType 变动类型
     * @param transactionSerialNo 交易流水号
     * @param amountRemark 备注
     * @param tag 用户来源
     * @return Integer
     */
    @Override
    public Integer saveWalletRecord(
            Long driverId,
            BigDecimal amount,
            Date date,
            Integer recordType,
            String transactionSerialNo,
            String amountRemark,
            String tag
            ) {

        OaDWalletRecord oaDWalletRecord = new OaDWalletRecord();
        oaDWalletRecord.setRecordId(IDUtil.nextId());
        oaDWalletRecord.setDriverId(driverId);
        oaDWalletRecord.setAmount(amount);
        oaDWalletRecord.setRecordType(recordType);
        oaDWalletRecord.setTransactionTime(date);
        oaDWalletRecord.setTransactionSerialNo(transactionSerialNo);
        oaDWalletRecord.setAmountRemark(amountRemark);
        oaDWalletRecord.setTag(tag);
        oaDWalletRecord.setCreateUser(driverId);
        oaDWalletRecord.setCreateTime(date);
        oaDWalletRecord.setUpdateUser(driverId);
        oaDWalletRecord.setUpdateTime(date);

        Integer walletRecordResult = oaDWalletRecordMapper.insert(oaDWalletRecord);

        return walletRecordResult;
    }

}
